/*
 *pdflib测试代码:
 *原作者的demo程序
 *Created on: 2019-7-9
 *Author: jun
 */
#include "spdf_ext.h"
#include "dataproc.h"
#include "math.h"
#include "str_ext.h"
#include "stdio.h"

extern SPDF_Doc pdf;
extern SPDF_Page page;
static short cnt;
extern SPDF_Doc_Rec pdf_doc;

/*****************************************************************************
 * @brief   spdf_char_form_tab_create 输出一页符号对照表.
 * @param   none
 * @return  none
 * @ Pass/ Fail criteria: none
 *****************************************************************************/
void spdf_char_form_tab_create(void)
{
	int cnt, gp;
	uint8_t buff[20];
	spdf_color_type fcolor, bcolor;

	spdf_form_type form = {0};

	page = spdf_add_page(pdf);
	sprintf((char *)buff, "chart table");
	spdf_outline_add(pdf, 0, page, 500, 500, (char *)buff, SPDF_ENCODING_ASCII);

	spdf_color_fill_rgb(98, 100, 100);
	spdf_rectangle(0, 0, spdf_page_get_width(page), spdf_page_get_height(page), 0x40);
	spdf_stroke_fill();

	spdf_form_page_mount(&form, page);

	spdf_page_push(page);
	spdf_page_line_dash_on(page, 35, 25, 0x21);

	spdf_page_line_end_mode(page, 1);

	form.frame.ext_dash_len1 = 30;
	form.frame.ext_dash_len0 = 20;
	form.frame.inn_dash_len1 = 10;
	form.frame.inn_dash_len0 = 30;

	for (gp = 1; gp <= 3; gp++)
	{
		spdf_form_col_set(&form, 4, 0, 40); // 列设置
		spdf_form_row_set(&form, 32, 24);	// 行设置
		spdf_form_frame_ext_set(&form, 100, 10, 10, 50);
		spdf_form_frame_inn_set(&form, 30, 40, 40, 80);
		spdf_form_text_offset(&form, 3, 5);
		spdf_form_text_font(&form, "SimSun", 180, 90);
		spdf_form_text_alain(&form, SPDF_FORM_ALAIN_MID);
		spdf_form_org(&form, 50 + 170 * (gp - 1), 40);

		spdf_form_draw(&form);
		spdf_form_text_start(&form);
		spdf_form_text_font(&form, "SimSun", 120, 60);

		spdf_page_color_fill_rgb_set(page, 100, 50, 0);

		fcolor.r = 0;
		fcolor.g = 30;
		fcolor.b = 60;
		bcolor.r = 100;
		bcolor.g = 70;
		bcolor.b = 40;
		for (cnt = 0x20 * gp; cnt < 0x20 * gp + 32; cnt++)
		{
			hex2_to_ascii(cnt, buff);
			buff[2] = 0;
			spdf_form_text_offset(&form, 3, 12);
			spdf_form_text_auto_ext(&form, (void *)buff, &bcolor, &fcolor);
			buff[0] = ((cnt >> 6) & 7) + '0';
			buff[1] = ((cnt >> 3) & 7) + '0';
			buff[2] = ((cnt >> 0) & 7) + '0';
			buff[3] = 0;
			spdf_form_text_offset(&form, 3, 2);
			spdf_form_text_auto(&form, (void *)buff);
			spdf_form_text_next_row(&form);
		}
		spdf_form_text_offset(&form, 3, 5);

		for (cnt = 0x20 * gp; cnt < 0x20 * gp + 32; cnt++)
		{
			buff[0] = cnt;
			buff[1] = 0;
			spdf_form_text_auto(&form, (void *)buff);
			spdf_form_text_next_row(&form);
		}

		spdf_form_text_font(&form, "Symbol", 200, 100);
		for (cnt = 0x20 * gp; cnt < 0x20 * gp + 32; cnt++)
		{
			buff[0] = cnt;
			buff[1] = 0;
			spdf_form_text_auto(&form, (void *)buff);
			spdf_form_text_next_row(&form);
		}
		spdf_form_text_font(&form, "ZapfDingbats", 200, 100);
		for (cnt = 0x20 * gp; cnt < 0x20 * gp + 32; cnt++)
		{
			buff[0] = cnt;
			buff[1] = 0;
			spdf_form_text_auto_ext(&form, (void *)buff, &bcolor, &fcolor);
			spdf_form_text_next_row(&form);
		}

		// 等宽坐标可以使用负标
		spdf_page_color_fill_rgb_set(page, 0, 30, 60);
		spdf_form_text_font(&form, "SimSun", 160, 80);

		fcolor.r = 0;
		fcolor.g = 30;
		fcolor.b = 60;
		bcolor.r = 100;
		bcolor.g = 70;
		bcolor.b = 40;
		spdf_form_text_ext(&form, -1, 0, "H/O", &bcolor, &fcolor);
		spdf_form_text(&form, -1, 1, "ASC");
		spdf_form_text(&form, -1, 2, "Sym");
		spdf_form_text_ext(&form, -1, 3, "Zap", &bcolor, &fcolor);

		// spdf_form_text_sp(&form, 0, 0, 5, 5, "num");

		spdf_form_text_end(&form);
	}

	// spdf_form_line_sp(&form, 0, 0, 0, 24,  40, 0);

	spdf_page_pop(page);

	spdf_page_save(page);
}
